package core;

import java.io.File;
import java.security.NoSuchAlgorithmException;

public class Usuario {

    private String nome;
    private char[] senha;

    public Usuario(String nome, char[] cs) {
	this.nome = nome;
	this.senha = cs;
    }

    public String getNome() {
	return nome;
    }

    public void setNome(String nome) {
	this.nome = nome;
    }

    public char[] getSenha() {
	return senha;
    }

    public void setSenha(char[] senha) {
	this.senha = senha;
    }

    public File getTaskFile() {

	return new File(Constantes.PASTA_USUARIO + File.separator + getHash() + ".tsk");
    }

    public String getHash() {
	byte[] hash = null;

	StringBuffer in = new StringBuffer(nome);
	in.append(senha);

	try {
	    hash = CriptoUtils.digest(in.toString().getBytes(), "MD5");
	} catch (NoSuchAlgorithmException e) {
	    e.printStackTrace();
	}

	String hex = CriptoUtils.byteArrayToHexString(hash);
	return hex;
    }

    public String getNomeHash() {
	byte[] hash = null;

	StringBuffer in = new StringBuffer(nome);

	try {
	    hash = CriptoUtils.digest(in.toString().getBytes(), "MD5");
	} catch (NoSuchAlgorithmException e) {
	    e.printStackTrace();
	}

	String hex = CriptoUtils.byteArrayToHexString(hash);
	return hex;
    }
}
